<%@ include file="common.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>Warehouse System</title>
    <meta charset="UTF-8">
    <%@ page contentType="text/html; charset=UTF-8" %>
</head>
<body>
<div class="container mt-5">
    <div class="jumbotron">
        <h1 class="display-4">Welcome to Warehouse System</h1>
        <p class="lead">This is a simple warehouse management system.</p>
        <hr class="my-4">
        <p>Choose your role:</p>
        <a id="adminButton" class="btn btn-primary btn-lg mr-3" role="button">管理员</a>
        <a id="userButton" class="btn btn-secondary btn-lg" role="button">员工</a>
    </div>
</div>

<!-- 管理员登录模态框 -->
<div class="modal fade" id="adminModal" tabindex="-1" role="dialog" aria-labelledby="adminModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="adminModalLabel">Administrator Login</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="adminLoginForm">
                    <div class="form-group">
                        <label for="adminUsername">Username</label>
                        <input type="text" class="form-control" id="adminUsername" required>
                    </div>
                    <div class="form-group">
                        <label for="adminPassword">Password</label>
                        <input type="password" class="form-control" id="adminPassword" required>
                    </div>
                    <div class="alert alert-danger d-none" id="adminError">Invalid credentials</div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="adminLogin">Login</button>
            </div>
        </div>
    </div>
</div>

<!-- 用户登录模态框 -->
<div class="modal fade" id="userModal" tabindex="-1" role="dialog" aria-labelledby="userModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="userModalLabel">User Login</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form id="userLoginForm">
                    <div class="form-group">
                        <label for="userUsername">Username</label>
                        <input type="text" class="form-control" id="userUsername" required>
                    </div>
                    <div class="form-group">
                        <label for="userPassword">Password</label>
                        <input type="password" class="form-control" id="userPassword" required>
                    </div>
                    <div class="alert alert-danger d-none" id="userError">Invalid credentials</div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" id="userLogin">Login</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function(){
        // 打开管理员模态框
        $("#adminButton").click(function(){
            $("#adminModal").modal('show');
        });

        // 打开用户模态框
        $("#userButton").click(function(){
            $("#userModal").modal('show');
        });

        // 管理员登录验证
        $("#adminLogin").click(function(){
            var username = $("#adminUsername").val();
            var password = $("#adminPassword").val();
            if(username === 'admin' && password === 'admin') {
                window.location.href = "${contextPath}/views/admin/index.jsp";
            } else {
                $("#adminError").removeClass('d-none');
            }
        });

        // 用户登录验证
        $("#userLogin").click(function(){
            var username = $("#userUsername").val();
            var password = $("#userPassword").val();
            if(username === 'user' && password === 'user') {
                window.location.href = "${contextPath}/views/user/index.jsp";
            } else {
                $("#userError").removeClass('d-none');
            }
        });
    });
</script>
</body>
</html>
